package net.tv90.bfmccore.util.HUD;

import lk.vexview.api.VexViewAPI;
import lk.vexview.gui.components.VexImage;
import lk.vexview.hud.VexImageShow;
import net.tv90.bfmccore.util.vector.Vector2i;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.Set;

public class ImageShow {
    public Vector2i imagePos;
    public Vector2i imageScale;
    public String imagePath;
    public int lastTime;
    public String name;

    public ImageShow(Vector2i imagePos, Vector2i imageScale, String imagePath, int lastTime, String name) {
        this.imagePos = imagePos;
        this.imageScale = imageScale;
        this.imagePath = imagePath;
        this.lastTime = lastTime;
        this.name = name;
    }

    public void show(Player p) {
        int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
        int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
        VexImage Icon = new VexImage(imagePath, imagePos.getX() * windowWidth / 854, imagePos.getY() * windowHeight / 445, imageScale.getX() * windowWidth / 854, imageScale.getY() * windowHeight / 445);
        VexViewAPI.sendHUD(p, new VexImageShow(name, Icon, lastTime));
    }

    public void showToPlayers(Set<Player> list) {
        list.forEach(p -> {
            int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
            int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
            VexImage Icon = new VexImage(imagePath, imagePos.getX() * windowWidth / 854, imagePos.getY() * windowHeight / 445, imageScale.getX() * windowWidth / 854, imageScale.getY() * windowHeight / 445);
            VexViewAPI.sendHUD(p, new VexImageShow(name, Icon, lastTime));
        });
    }

    public void showToAllPlayers() {
        Bukkit.getOnlinePlayers().forEach(p -> {
            int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
            int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
            VexImage Icon = new VexImage(imagePath, imagePos.getX() * windowWidth / 854, imagePos.getY() * windowHeight / 445, imageScale.getX() * windowWidth / 854, imageScale.getY() * windowHeight / 445);
            VexViewAPI.sendHUD(p, new VexImageShow(name, Icon, lastTime));
        });
    }
}
